namespace dragonBones.phaser.display {
    // this class will be refactored due to official Container will be removed soon.
    export class DisplayContainer extends Phaser.GameObjects.Container {
        private tempTransformMatrix: util.TransformMatrix;
        constructor(scene: Phaser.Scene, x?: number, y?: number, children?: Phaser.GameObjects.GameObject[]) {
            super(scene, x, y, children);
            this.tempTransformMatrix = new util.TransformMatrix();
        }

        pointToContainer(source: Phaser.Math.Vector2 | Phaser.Geom.Point | { x?: number, y?: number},
                        output?: Phaser.Math.Vector2 | Phaser.Geom.Point | { x?: number, y?: number}): Phaser.Math.Vector2 | Phaser.Geom.Point | { x?: number, y?: number} {
            if (output === undefined)
                output = new Phaser.Math.Vector2();

            if (this.parentContainer)
                return this.parentContainer.pointToContainer(source, output);

            const tempMatrix = this.tempTransformMatrix;

            //  No need to loadIdentity because applyITRS overwrites every value anyway
            tempMatrix.applyITRS(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.skewX, this.skewY);

            tempMatrix.invert();

            tempMatrix.transformPoint(source.x, source.y, output);

            return output;
        }
    }

    // util.extendSkew(DisplayContainer);  // skew mixin
}
